﻿using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;
using Zocono.WCS.Domain.DomainRepository;
using Zocono.WCS.Domain.EntityInfo;
using Zocono.WCS.Infrastructure.ApllicationDto;
using Zocono.WCS.Infrastructure.ApllicationDto.DtoWcsManage;
using Zocono.WMS.Infrastructure.BaseRepository;

namespace Zocono.WCS.Infrastructure.Repository
{
    public class ElevatorJudgeInfoRepository:BaseRepository<ElevatorJudgeInfo>, IElevatorJudgeInfoRepository
    {
        public ElevatorJudgeInfoRepository(SqlSugarClient context = null) : base(context)
        {

        }

        public  async Task<PageDto<ElevatorJudgeInfoDto>> GetElevatorJudgeInfosAsync(Expression<Func<ElevatorJudgeInfo, bool>> exp, PageModel page)
        {
            PageDto<ElevatorJudgeInfoDto> pageDto = new PageDto<ElevatorJudgeInfoDto>();
            RefAsync<int> totalNumber = 0;
            var result = await Context.Queryable<ElevatorJudgeInfo>()
                .Where(exp)
                .Select(l => new ElevatorJudgeInfoDto
                {
                    ID = l.ID,
                    ElevatorCode = l.ElevatorCode,
                    NextElevatorCode = l.NextElevatorCode,
                    EquipmentDO = l.EquipmentDO,
                    EquipmentPU = l.EquipmentPU,
                    NextEquipmentPU = l.NextEquipmentPU,
                    IsThisBothway = l.IsThisBothway,
                    IsNextBothway = l.IsNextBothway,
                    JudgeEquipmentCode = l.JudgeEquipmentCode,
                    IsEnable=l.IsEnable,
                    IsNextEnd=l.IsNextEnd
                } ).ToPageListAsync(page.PageIndex, page.PageSize, totalNumber);

            pageDto.Result = result;
            pageDto.Total = totalNumber;
            return pageDto;
        }
    }
}
